<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@page import="com.shiyue.sywesp.bean.User"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+"/";
%>
<!-- 登陆页面 -->
<html>
  <head>
    <title>登录SYWESP</title>
	<link href="css/index_css.css" rel="stylesheet" type="text/css" />
	<script src="<%=path%>/js/syAjax.js"></script>
	<script type="text/javascript">
	if(self!=top) top.location=self.location;
    window.onload = function(){
    $('account').focus();
     }
     

	//添加Ajax验证
	function doLogin()
	{
		//var inputLength = document.getElementById("password").value.length;
		//if(inputLength==6){
			syAjax.request("post","<%=path%>/checkLoginFailCountUserAction.action","user.account="+document.getElementById("account").value,{success:function (response){	
				if(parseInt(response)>=5){
					alert("帐号已被锁定或您输入的信息有误");
					document.getElementById("password").value="";
				}else{
					syAjax.request("post","<%=path%>/loginCheckUserAction.action","user.account="+document.getElementById("account").value+"&user.password="+document.getElementById("password").value,{success:initSuccessResult,fail:onFail,type:'plain'});		
				}
				
				
				
				
			},fail:onFail,type:'plain'});	
			 
		//}
		 
	}
	
	
	function initSuccessResult(response){
	if(null!=response){
		var reponseArr = response.split("_");
			
	//输入的信息有误
	    if(reponseArr[0]=="loginfail")
	    {
	        
	    	alert("登录失败！您输入的信息有误！");
	    	document.getElementById("password").value="";
	    }
	    else
	    {	    
		        if(0==reponseArr[1]){
		        	window.location.href="<%=path%>/toShowTermsOfServiceTermsOfServiceAction.action?myresponse="+reponseArr[0];
		        }else{
				    if(reponseArr[0]=="teacher")
				    {
				    	window.location.href="<%=path%>/teacher/index.jsp";
				    	
				    }
				   else if(reponseArr[0]=="student")
				    {
				    	window.location.href="<%=path%>/student/index.jsp";
				    }
		        }	
	    }
	    
	    }
	    
	}
	
	
	function passwordOnKeyDown(e){
		if(e.keyCode==13){
		   doLogin();
		}
	}
	

	</script>
  </head>
  <body>
    <table width="848" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="848" height="20" colspan="2">&nbsp;</td>
  </tr>
</table>

<table width="848" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
   
    <td align="left" valign="top"><br><table width="100%"  border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td align="left" ><br><br><img src="<%=path %>/images/sywesp_3.gif" width="376" height="29" /></td>
      </tr>
      <tr>
        <td align="center"  background="<%=path %>/images/sywesp_5.gif"><table width="90%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td height="25" colspan="3" align="left"><img src="<%=path %>/images/sywesp_6.gif" width="271" height="29" border="0" /></td>
            </tr>
          <tr>
            <td height="35" align="right" valign="bottom">用户名&nbsp;</td>
            <td align="left" valign="bottom"><input name="user.account"  id="account" type="text" value="${requestScope.cookieName}"  style="width:150px" onFocus="this.select()" onKeyDown="if(event.keyCode==13)event.keyCode=9"/></td>
            <td valign="bottom">&nbsp;</td>
          </tr>
          <tr>
            <td height="35" align="right" valign="bottom">密码&nbsp;</td>
            <td align="left" valign="bottom"><input name="user.password" id="password" type="password" style="width:150px" value="${requestScope.cookiePassword }" onKeyDown="passwordOnKeyDown(event);"   />
            <a href="<%=path %>/baseSet/user/getPassword_a.jsp" style="text-decoration: none;">忘记密码了?</a></td>
          </tr>
       
         
       
        </table>          </td>
      </tr>
      <tr>
        <td align="left" valign="top"><img src="<%=path %>/images/sywesp_4.gif" width="377" height="10" /></td>
      </tr>
    </table></td>
  </tr>
</table>

</body>
</html>
